<%@ page pageEncoding="UTF-8"%>

<%@ taglib uri="/tags/struts-tiles" prefix="tiles"%>
<%@ taglib uri="/tags/struts-html" prefix="html"%>
<%@ taglib uri="/tags/struts-logic" prefix="logic"%>
<%@ taglib uri="/tags/struts-nested" prefix="nested"%>
<%@ taglib uri="/tags/struts-bean" prefix="bean"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix='fmt'%>
<%@ taglib uri="/tags/trymore" prefix="tm"%>

<script>
	function afterRemove()
	{
		alertMsg.correct("材料删除成功...")
		
		// 重新加载当前弹框页面数据
		var dialogs = $(".dialog");
		if ($.pdialog._current != null) {
			//$("li.selected", $.pdialog._current).trigger("click");
			$.pdialog.reload("app/project/base.do?action=dialogProjectPage&pid=${pid}&op=post_stuff&currentindex=1");
		}
		
	}
</script>

<style>
	table.datalst td {line-height: 35px;}
</style>

<div class="pageFormContent" layoutH="${pid ne null ? (flag ne null ? 58 : 95) : 55}" style="border-top: none; background-color: #FFF">

	<div style="margin: 10px 0;" align="right">
		<table>
			<tr>
				<c:if test="${tm:inRange(entity.projectRelevantPersonIds, sessionScope.SPRING_SECURITY_CONTEXT.authentication.principal.id, ',') || tm:inRange('ROLE_SUPER,ROLE_ADMIN,ROLE_PROJECT_MASTER,ROLE_PROJECT_ASSISTANT', sessionScope.SPRING_SECURITY_CONTEXT.authentication.principal.roleKey, ',')}">
					<td><a href="app/project/base.do?action=actionPackMaterail&pid=${pid}" target="_blank" class="oplink" style="text-decoration: none; color: #AD1B1B; margin-right: 5px; background: url('resources/images/icon-pkg.png') no-repeat scroll 0 0 transparent" rel="external">打包下载</a></td>
				</c:if>
				
				<c:if test="${op ne null && op eq 'post_stuff'}">
					<c:if test="${tm:inRange(entity.projectRelevantPersonIds, sessionScope.SPRING_SECURITY_CONTEXT.authentication.principal.id, ',')}">
						<td width="60px" align="right">
							<a href="app/project/base.do?action=dialogProjectAddMaterial&pid=${pid}" 
								target="dialog" title="添加材料" class="oplink" style="text-decoration: none; color: #AD1B1B; margin-right: 5px" width="350" height="260">添加材料</a>
						</td>
					</c:if>
				</c:if>
			</tr>
		</table>
	</div>
	
	<!-- Body -->	
	<div class="pageContent">
		<table class="datalst" rules="all" bordercolor="#CCC" width="100%"  style="height:auto">
			<thead>
				<tr>
					<th align="center">材料分类</th>
					<th align="center">材料名称</th>
					<th align="center">材料描述</th>
					<th align="center">预览与下载</th>
					<th align="center">材料性质</th>
					<th align="center">材料状态</th>
					<th align="center">提交人</th>
					<th align="center">最新提交时间</th>
					<th align="center">历史版本</th>
					<c:if test="${op eq null || (op ne 'view' && op ne 'allocate')}">
					<th align="center">操作</th>
					</c:if>
				</tr>
			</thead>
			<tbody>
				<logic:present name="materials">
					<logic:iterate name="materials" id="material" indexId="idx">
						<tr ${idx % 2 == 1 ? 'style="background-color: #F5F5F5"' : ''}>
							<td rowspan="${fn:length(material.materialChildren)}" style="background-color: #CFDBEC">${material.materialName}</td>
							<c:choose>
								<c:when test="${fn:length(material.materialChildren) gt 0}">
									<logic:iterate name="material" property="materialChildren" id="node" offset="0" length="1">
										<td style="text-align:left; padding-left: 3px">${node.materialName}</td>
										<td style="text-align:left; padding-left: 3px">${node.materialDesc}</td>
										<td>
											<c:choose>
												<c:when test="${node.latestUploadMeta ne null}">
													<!--<a href="app/base.do?action=actionViewDocOnline&filePath=${node.latestUploadMeta.attachment.filePath}&fileName=${node.latestUploadMeta.attachment.fileName}" target="dialog" title="`${node.materialName}`在线预览" class="oplink">预览</a>
													&nbsp;
													-->
													<c:choose>
														<c:when test="${tm:inRange(entity.projectRelevantPersonIds, sessionScope.SPRING_SECURITY_CONTEXT.authentication.principal.id, ',') || tm:inRange('ROLE_SUPER,ROLE_ADMIN,ROLE_PROJECT_MASTER,ROLE_PROJECT_ASSISTANT', sessionScope.SPRING_SECURITY_CONTEXT.authentication.principal.roleKey, ',')}">
															<a href="file-download?path=${node.latestUploadMeta.attachment.filePath}&filename=${node.latestUploadMeta.attachment.fileName}" target="_blank" class="oplink">下载</a>
														</c:when>
														<c:otherwise>
															<label style="float:none; padding:none" class="opdisabled" title="只有项目经理或项目参与人员可以进行`下载`操作">下载</label>
														</c:otherwise>
													</c:choose>
												</c:when>
												<c:otherwise>
													<!--<label style="float:none; padding:none" class="opdisabled" title="尚未提交任何文件, 不能进行预览操作">预览</label>
													&nbsp;-->
													<label style="float:none; padding:none" class="opdisabled" title="尚未提交任何文件, 不能进行下载操作">下载</label>
												</c:otherwise>
											</c:choose>
										</td>
										<td style="background-color: ${node.materialType eq 1 ? '#D9896A' : (node.materialType eq 0 ? '#3FA156' : '#DDD')}">${node.materialType eq 1 ? '* 必须提交' : (node.materialType eq 0 ? '建议提交' : '补充提交')}</td>
										<td>${node.latestUploadMeta.poster ne null ? '已提交' : '未提交'}</td>
										<td>
											<c:choose>
												<c:when test="${node.latestUploadMeta ne null}">${node.latestUploadMeta.poster ne null ? node.latestUploadMeta.poster.username : '---'}</c:when>
												<c:otherwise>---</c:otherwise>
											</c:choose>
										</td>
										<td>
											<c:choose>
												<c:when test="${node.latestUploadMeta ne null}"><fmt:formatDate value="${node.latestUploadMeta.creationTime}" type="date" pattern="yyyy-MM-dd HH:mm:ss"/></c:when>
												<c:otherwise>---</c:otherwise>
											</c:choose>
										</td>
										<td>
											<a href="app/project/base.do?action=dialogProjectMaterialRepository&mid=${node.id}" target="dialog" title="`${node.materialName}`历史版本" class="oplink" width="900" height="500">历史版本</a>
										</td>
										<c:if test="${op eq null || (op ne 'view' && op ne 'allocate')}">
										<td>
											<a href="app/project/base.do?action=dialogProjectAddMaterial&pid=${entity.id}&mid=${node.id}" mask="true" target="dialog" title="`${node.materialName}`材料上传" class="oplink" width="350" height="260">添加</a>
											&nbsp;
											<a href="app/project/base.do?action=actionRemoveMaterails&mid=${node.id}" target="ajaxTodo" title="确定要删除`${node.materialName}`所有材料么？" class="oplink" callback="afterRemove()">删除</a>
										</td>
										</c:if>
									</logic:iterate>
								</c:when>
								<c:otherwise>
									<td></td>
									<td></td>
									<td></td>
									<td></td>
									<td></td>
									<td></td>
									<td></td>
									<td></td>
									<c:if test="${op eq null || op ne 'view'}">
									<td></td>
									</c:if>
								</c:otherwise>
							</c:choose>			
						</tr>
						<c:if test="${fn:length(material.materialChildren) gt 1}">
							<logic:iterate name="material" property="materialChildren" id="node" offset="1">
								<tr>
									<td style="text-align:left; padding-left: 3px">${node.materialName}</td>
									<td style="text-align:left; padding-left: 3px">${node.materialDesc}</td>
									<td>
										<c:choose>
											<c:when test="${node.latestUploadMeta ne null}">
												<!--<a href="app/base.do?action=actionViewDocOnline&filePath=${node.latestUploadMeta.attachment.filePath}&fileName=${node.latestUploadMeta.attachment.fileName}" target="dialog" title="`${node.materialName}`在线预览" class="oplink">预览</a>
												&nbsp;
												-->
												<c:choose>
													<c:when test="${tm:inRange(entity.projectRelevantPersonIds, sessionScope.SPRING_SECURITY_CONTEXT.authentication.principal.id, ',') || tm:inRange('ROLE_SUPER,ROLE_ADMIN,ROLE_PROJECT_MASTER,ROLE_PROJECT_ASSISTANT', sessionScope.SPRING_SECURITY_CONTEXT.authentication.principal.roleKey, ',')}">
														<a href="file-download?path=${node.latestUploadMeta.attachment.filePath}&filename=${node.latestUploadMeta.attachment.fileName}" target="_blank" class="oplink">下载</a>
													</c:when>
													<c:otherwise>
														<label style="float:none; padding:none" class="opdisabled" title="只有项目经理或项目参与人员可以进行`下载`操作">下载</label>
													</c:otherwise>
												</c:choose>
											</c:when>
											<c:otherwise>
												<!--<label style="float:none; padding:none" class="opdisabled" title="尚未提交任何文件, 不能进行预览操作">预览</label>
												&nbsp;-->
												<label style="float:none; padding:none" class="opdisabled" title="尚未提交任何文件, 不能进行下载操作">下载</label>
											</c:otherwise>
										</c:choose>
									</td>
									<td style="background-color: ${node.materialType eq 1 ? '#D9896A' : (node.materialType eq 0 ? '#3FA156' : '#DDD')}">${node.materialType eq 1 ? '* 必须提交' : (node.materialType eq 0 ? '建议提交' : '补充提交')}</td>
									<td>${node.latestUploadMeta.poster ne null ? '已提交' : '未提交'}</td>
									<td>
										<c:choose>
											<c:when test="${node.latestUploadMeta ne null}">${node.latestUploadMeta.poster ne null ? node.latestUploadMeta.poster.username : '---'}</c:when>
											<c:otherwise>---</c:otherwise>
										</c:choose>
									</td>
									<td>
										<c:choose>
											<c:when test="${node.latestUploadMeta ne null}"><fmt:formatDate value="${node.latestUploadMeta.creationTime}" type="date" pattern="yyyy-MM-dd HH:mm:ss"/></c:when>
											<c:otherwise>---</c:otherwise>
										</c:choose>
									</td>
									<td>
										<a href="app/project/base.do?action=dialogProjectMaterialRepository&mid=${node.id}" target="dialog" title="`${node.materialName}`历史版本" class="oplink" width="900" height="500">历史版本</a>
									</td>
									<c:if test="${op eq null || (op ne 'view' && op ne 'allocate')}">
									<td>
										<c:choose>
											<c:when test="${tm:inRange(entity.projectRelevantPersonIds, sessionScope.SPRING_SECURITY_CONTEXT.authentication.principal.id, ',')}">
												<a href="app/project/base.do?action=dialogProjectAddMaterial&pid=${entity.id}&mid=${node.id}" mask="true" target="dialog" title="`${node.materialName}`材料上传" class="oplink" width="350" height="260">添加</a>
												&nbsp;
												<a href="app/project/base.do?action=actionRemoveMaterails&mid=${node.id}" target="ajaxTodo" title="确定要删除`${node.materialName}`所有材料么？" class="oplink" callback="afterRemove()">删除</a>
											</c:when>
											<c:otherwise>
												<label style="float:none; padding:none" class="opdisabled" title="只有项目经理或项目参与人员可以进行`添加`操作">添加</label>
												&nbsp;
												<label style="float:none; padding:none" class="opdisabled" title="只有项目经理或项目参与人员可以进行`删除`操作">删除</label>
											</c:otherwise>
										</c:choose>
									</td>
									</c:if>
								</tr>
							</logic:iterate>
						</c:if>
					</logic:iterate>
				</logic:present>
			</tbody>
		</table>
	</div>
</div>